<?php $this->load->view('layout/header'); ?>
<div class="supplier-content-page">
    <div class="product-test-h5">
        <ul class="breadcrumb">
            <li><a href="javascript:;">站点管理</a></li>
            <li class="active"><a href="javascript:;">幻灯片广告管理</a></li>
        </ul>
        <?php echo execute_alert_message() ?>
        <div class="product-alls">
            <div class="product-fonter">编辑广告</div>
            <div class="add-form">
            	<form class="form-horizontal" action="<?php echo site_url('advert/editPost') ?>" method="post"
                  id="advert_add">
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><em>* </em>标题</label>
                        <div class="col-xs-10">
                            <input type="text" name="title" class="form-control required" placeholder="标题" value="<?php echo $advert->title;?>"/>
                            <input type="hidden" name="id" value="<?php echo $advert->id; ?>"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"> &nbsp;&nbsp;&nbsp;展示位置</label>
                        <div class="col-xs-5">
                            <?php foreach ( $position as $k=>$v):?>
                            <label class="radio-inline">
                                <input type="radio" name="position" value="<?php echo $k;?>" <?php if ($k == $advert->position): echo 'checked';endif;?> /><?php echo $v;?>
                            </label>
                            <?php endforeach;?>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><em>* </em>跳转类型</label>
                        <div class="col-xs-5">
                            <?php foreach ( $opentype as $k=>$v):?>
                            <label class="radio-inline">
                                <input type="radio" name="opentype" value="<?php echo $k;?>" class="required" <?php if ($k == $advert->opentype): echo 'checked';endif;?> /><?php echo $v;?>
                            </label>
                            <?php endforeach;?>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><em>* </em>打开参数</label>
                        <div class="col-xs-10">
                            <input type="text" name="openvar" class="form-control required url" placeholder="打开参数" value="<?php echo $advert->openvar;?>" />
                        </div>
                    </div>
                    <div class="form-group file-images-add">
                        <label class="col-sm-1 control-label"><em>* </em>图片</label>
                        <div class="col-xs-10 file-images">
                            <img src="<?php echo $this->config->show_image_url($advert->picture); ?>" width=110 height="100">
                            <input type="file" name="picture" >
                            <input type="hidden" name="picture" value="<?php echo $advert->picture;?>"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><em>* </em>状态</label>
                        <div class="col-xs-5">
                            <label class="radio-inline">
                                <input type="radio" name="status" value="1" class="required" <?php if ($advert->status==1): echo 'checked'; endif;?> />启用
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="status" value="0" class="required" <?php if ($advert->status==0): echo 'checked'; endif;?> />禁用
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"><em>* </em>排序</label>
                        <div class="col-xs-3">
                            <input type="text" name="sort" class="form-control number required" value="<?php echo $advert->sort;?>">
                        </div>
                    </div>
                    <div class="sup-submit">
                    <button type="submit" class="btn btn-default">保存</button>
                    <a href="<?php echo site_url('advert/grid'); ?>">返回上一级</a>
                	</div>
            	</form>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer'); ?>
<script type="text/javascript">
    $('#advert_add').validate();
    
    $('button.btn-info').click(function () {
        if (!$('#advert_add').valid()) {
            return false;
        }
    });
    
    $('.form-horizontal').on('change', 'input[type=file]', function (e) {
        var $this = $(this);
        upLoadImg(e.currentTarget.files[0], function (obj) {
            console.log(obj);
            $this.siblings('[type=hidden]').val(obj.save_path);
            $this.parents('.file-images').children('img').attr('src', obj.file_url);
        });
    });
</script>